package com.itheima.netty.c4;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

@Slf4j
public class TestJdkFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 1.线程池
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        // 2.提交
        Future<Integer> future = executorService.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.info("执行计算");
                Thread.sleep(3000);
                return 50;
            }
        });
        // 3.主线程它通过future获取结果
        log.info("等待结果");
        log.info("{}",future.isDone());

        //get阻塞方法,将主线程阻塞等待，任务完成获得返回值，继续向下执行
        Integer integer = future.get();
        log.info("结果是{}",integer);
    }
}
